package com.gaogzhen.datastructure.linear;

import cn.hutool.crypto.digest.MD5;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.util.Arrays;
import java.util.Iterator;

/**
 * @author Administrator
 * @version 1.0
 * @description test linear list
 * @date 2022-10-04 21:39
 */
public class TestLinearList {
    public static void main(String[] args) {

        testJusephus();
    }

    public static void testJusephus() {
        // 初始化链表
        int size = 8, start = 5, count = 3;
        CircularList<Integer> jusephus = new CircularList<>();
        for (int i = 1; i <= size; i++) {
            jusephus.add(i);
        }
        System.out.println("初始数据:" + jusephus);
        int index = (start + count - 2);
        int[] nums = new int[size];
        int i = 0;
        int tsize = size;
        while (!jusephus.isEmpty()) {
            if (index > tsize - 1 ) {
                index = index % tsize;
            }
            int tmp = jusephus.remove(index);
            System.out.println(tmp);
            nums[i++] = tmp;
            index = index + count - 1;
            tsize--;
        }
        System.out.println("出队编号：" + Arrays.toString(nums));
        System.out.println("最终数据:" + jusephus);
    }
    // 7
    public static void testCircularList() {
        CircularList<Integer> slj = new CircularList<>();
        slj.add(22);
        slj.add(5242);
        slj.add(52);
        System.out.println(slj);
        System.out.println("原数组大小: " + slj.size() );
//        System.out.println("====移除索引为0的元素: " + slj.remove(0));
//        System.out.println("====移除索引为0的元素: " + slj.remove(0));
//        System.out.println("====移除索引为0的元素: " + slj.remove(0));
//        System.out.println("====移除索引为1的元素: " + slj.remove(1));
        System.out.println(slj);
        System.out.println("移除后数组大小: " + slj.size());

        Iterator<Integer> iterator = slj.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }

    public void test1() {

    }

    public static void testEncoder() {
        MD5 md5 = MD5.create();
        String s = md5.digestHex("123456".getBytes());
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        System.out.println(passwordEncoder.matches("able56885", "$2a$10$XEDvuHmFT148WJPEVE1BleoWV7veKt8K4Uvf.hTrCKbygXmi/FDiu"));
        System.out.println(passwordEncoder.encode(s));
        System.out.println(passwordEncoder.encode(s).equals("$2a$10$XEDvuHmFT148WJPEVE1BleoWV7veKt8K4Uvf.hTrCKbygXmi/FDiu"));
    }

    public static void testReverse() {
        LinkList<Integer> slj = new LinkList<>();
        slj.add(1);
        slj.add(2);
        slj.add(3);
        slj.add(4);
        System.out.println("===反转前====");
        System.out.println(slj);
        slj.reverse();
        System.out.println("===反转后====");
        System.out.println(slj);
    }

    public static void testLinkList() {
        LinkList<Integer> slj = new LinkList<>();
        slj.add(22);
        slj.add(5242);
        slj.add(52);
        System.out.println(slj);
        System.out.println("原数组大小: " + slj.size() );
        System.out.println("====移除索引为0的元素: " + slj.remove(0));
//        System.out.println("====移除索引为1的元素: " + slj.remove(1));
        System.out.println(slj);
        System.out.println("移除后数组大小: " + slj.size());

        Iterator<Integer> iterator = slj.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }

    public static void testSequenceList() {
        SequenceListJunior<Integer> slj = new SequenceListJunior<>(5);
        slj.add(22);
        slj.add(5242);
        slj.add(52);
        System.out.println(slj);
        System.out.println("原数组大小: " + slj.size() );
        System.out.println("====移除索引为0的元素: " + slj.remove(0));
        System.out.println(slj);
        System.out.println("移除后数组大小: " + slj.size());
    }

}
